package com.example.tiku2;

import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.widget.TextView;

import com.example.tiku2.adapter.VpFragmentAdapter;
import com.example.tiku2.bean.ProjectBean;

import java.util.ArrayList;

public class Main2Activity extends AppCompatActivity {

    private TextView tv_toolbar;
    private Toolbar toolbar;
    private ViewPager vp;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        initView();
        initVp();
    }

    private void initVp() {
        ArrayList<ProjectBean.DataBean.DatasBean> list =
                (ArrayList<ProjectBean.DataBean.DatasBean>) getIntent().getSerializableExtra("list");
        ArrayList<VpFragment> fs = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            VpFragment vf = new VpFragment();
            Bundle b = new Bundle();
            b.putString("imgUrl", list.get(i).getEnvelopePic());
            b.putInt("page", i);
            b.putInt("allPage", list.size());
            vf.setArguments(b);
            fs.add(vf);
        }
        VpFragmentAdapter adapter = new VpFragmentAdapter(getSupportFragmentManager(), fs);
        vp.setAdapter(adapter);
    }

    private void initView() {
        tv_toolbar = (TextView) findViewById(R.id.tv_toolbar);
        toolbar = (Toolbar) findViewById(R.id.toolbar);
        vp = (ViewPager) findViewById(R.id.vp);

        toolbar.setTitle("");
        setSupportActionBar(toolbar);
    }
}
